﻿using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace EAMF.Content.Projectiles
{
    public class ArrowProj : ModProjectile
    {
        public override void SetDefaults()
        {
            Projectile.width = 74;
            Projectile.height = 25;
            Projectile.timeLeft = 200;
            base.SetDefaults();
        }
        public override void AI()
        {
            int mode = 2;
            Projectile.rotation = Projectile.velocity.ToRotation();
            switch (mode)
            {
                default:
                    break;
                case 0:
                    {
                        if (Projectile.timeLeft < 170)
                        {
                            Projectile.velocity *= 0.9f;
                            Projectile.scale *= 0.9f;
                        }
                    }
                    break;
                case 1:
                    {
                        //每60帧改变一下方向
                        if (Projectile.timeLeft % 60 == 0)
                        {
                            Projectile.velocity = Projectile.velocity.RotatedByRandom(3.14f);//
                        }
                    }
                    break;
                case 2:
                    {
                        //速度线性减少
                        float factor = 1f - Projectile.timeLeft / 200f;
                        Vector2 unitV = Vector2.Normalize(Projectile.velocity); //单位速度
                        Projectile.velocity = 10f * unitV * (1f - factor);
                        Projectile.scale *= (1f - factor);
                    }
                    break;
                case 3:
                    {
                        //速度以正抛物线减速
                        float factor = 1 - Projectile.timeLeft / 200;
                        factor *= factor;//先慢后快
                        Vector2 unit = Vector2.Normalize(Projectile.velocity);
                        Projectile.velocity = 10f * unit * (1 - factor);
                        Projectile.scale *= (1f - factor);
                        break;
                    }   
            }

            base.AI();
        }
    }
}
